package com.cloud.common.core.configure;

import com.cloud.common.core.handler.MyAccessDeniedHandler;
import com.cloud.common.core.handler.MyAuthExceptionEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

/**
 * @Description:
 * @Auther: zhangxun
 * @Date: 2020/8/11 18:04
 *
 */
public class AuthExceptionConfigure {
    @Bean
    @ConditionalOnMissingBean(name = "accessDeniedHandler")
    public MyAccessDeniedHandler accessDeniedHandler() {
        return new MyAccessDeniedHandler();
    }

    @Bean
    @ConditionalOnMissingBean(name = "authenticationEntryPoint")
    // @ConditionalOnMissingBean注解的意思是，当IOC容器中没有指定名称或类型的Bean的时候，就注册它。
    // 这样做的好处在于，子系统可以自定义自个儿的资源服务器异常处理器，覆盖我们在febs-common通用模块里定义的。
    public MyAuthExceptionEntryPoint authenticationEntryPoint() {
        return new MyAuthExceptionEntryPoint();
    }
}